package top.goldenyear.porpoise.infra.job.controller.admin;

import java.util.List;
import lombok.extern.slf4j.Slf4j;
import org.noear.solon.annotation.*;
import top.goldenyear.porpoise.common.core.model.Ret;
import top.goldenyear.porpoise.framework.web.core.controller.BaseController;
import top.goldenyear.porpoise.framework.web.core.model.query.QPage;
import top.goldenyear.porpoise.infra.job.model.Job;
import top.goldenyear.porpoise.infra.job.service.JobService;

/**
 * 定时任务表 Controller 控制层
 *
 * @author airhead
 * @since 2024-12-21
 */
@Component(tag = "admin")
@Mapping("/job")
@Slf4j
public class JobAdminController extends BaseController {
  @Inject private JobService service;

  @Post
  @Mapping("create")
  public Ret create(@Body Job job) {
    return Ret.okWithData(service.createJob(job));
  }

  @Post
  @Put
  @Mapping("update")
  public Ret update(@Body Job job) {
    return Ret.okWithData(service.updateJob(job));
  }

  @Post
  @Put
  @Mapping("toggle")
  public Ret toggle(@Param Long id, @Param Boolean status) {
    return Ret.okWithData(service.toggleJob(id, status));
  }

  @Get
  @Mapping("get")
  public Ret get(@Param Long id) {
    return Ret.okWithData(service.getJob(id));
  }

  @Post
  @Delete
  @Mapping("delete")
  public Ret delete(@Param Long id) {
    return Ret.okWithData(service.deleteJob(id));
  }

  @Post
  @Delete
  @Mapping("batchDel")
  public Ret batchDel(@Param List<Long> ids) {
    return Ret.okWithData(service.batchDelJob(ids));
  }

  @Get
  @Mapping("paginate")
  public Ret paginate(QPage qPage) {
    Job job = getBean(Job.class);
    return Ret.okWithData(service.paginateJob(qPage, job));
  }

  @Get
  @Mapping("list")
  public Ret list() {
    Job job = getBean(Job.class);
    return Ret.okWithData(service.listJob(job));
  }

  //  @Get
  //  @Mapping("simpleList")
  //  public Ret simpleList() {
  //    Job job = getBean(Job.class);
  //    return Ret.okWithData(service.simpleListJob(job));
  //  }

  //  @Get
  //  @Mapping("options")
  //  public Ret options() {
  //    Job job = getBean(Job.class);
  //
  //    return Ret.okWithData(service.optionsJob(dictCode));
  //  }
}
